iT邦幫忙

2

Python學習筆記: 快速產生常態分佈(Normal distribution)的學生成績-源自ChatGPT

  • 分享至 

  • xImage
  •  

本文同步發表於小弟自架網站:微確幸資訊站

以下程式碼源自於ChatGPT,主要變數說明如下:
n_students:學生人數
n_exams:考試科目數
mean:考試成績平均數
std_dev:考試成績標準差

import pandas as pd
import numpy as np

# Set the number of students and the number of exams
n_students = 20
n_exams = 5

# Set the mean and standard deviation for the normal distribution
mean = 70
std_dev = 10

# Generate the random scores using numpy
scores = np.random.normal(loc=mean, scale=std_dev, size=(n_students, n_exams))

# Create a pandas DataFrame to store the scores
df = pd.DataFrame(scores)

# Set the column names
df.columns = ['Exam ' + str(i+1) for i in range(n_exams)]

# Set the row names as the student IDs
df.index = ['Student ' + str(i+1) for i in range(n_students)]

# Print the DataFrame
print(df)

https://ithelp.ithome.com.tw/upload/images/20230303/20122335L4RNPqTRQi.jpg


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言